package com.faithnmn.learnenglishbc.network;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.json.JSONObject;

import android.content.Context;
import android.util.Log;

import com.android.volley.Request.Method;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.JsonObjectRequest;

public class NetworkExecutor {
	private static NetworkExecutor instance;
	private Context context;
	private RequestQueue requestQueue;
	public static NetworkExecutor getInstance() {
		if (instance == null) {
			synchronized (NetworkExecutor.class) {
				if (instance == null) {
					instance = new NetworkExecutor();
				}
			}
		}
		return instance;
	}
	
	public NetworkExecutor init(Context context){
        this.context = context;
        requestQueue = VolleyRequestManager.getRequestQueue();
        return this;
    }
	
	public void getNewsFeedPost(int LIMIT,Response.Listener<JSONObject> responseSuccessListener,Response.ErrorListener responseErrorListener){
		String url = "https://graph.facebook.com/fql?q=";
		String params = "select object_id,caption,src_big,like_info,comment_info,created FROM photo WHERE owner = '131304647058701'" +
//				" and (strpos(caption, '[TiengAnh]') >=0 or strpos(caption, '[HocTiengAnh]') >= 0) LIMIT " + LIMIT;
				"  LIMIT " + LIMIT;
		String endpoint = "";
		try {
			endpoint = url + URLEncoder.encode(params, "UTF-8");
			Log.e("Endpoint", "Endpoint:"+endpoint);
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		}
		JsonObjectRequest jr = new JsonObjectRequest(Method.GET, endpoint,null, responseSuccessListener, responseErrorListener,null);
		requestQueue.add(jr);
	}
}
